package com.mingzhi.forum.controller;

import com.mingzhi.forum.exception.ApplicationException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@Tag(name = "TestController接口测试")
//表示返回的是数据，ResponseBody
@RestController
@RequestMapping("/test")  // 以及映射路径
public class TestController {

    @Operation(summary = "测试接口4,按照传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    public String helloByName(@Parameter(name = "name",description = "姓名") @RequestParam("name") String name){
        return "常明乾说：" + name;
    }

    @Operation(summary = "测试接口3，返回一个异常")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是一个Exception");
    }

    @Operation(summary = "测试接口2，返回一个自定义的异常")
    @PostMapping("/appException")
    public String testApplicationException(){
        throw new ApplicationException("这是一个自定义的ApplicationException");
    }

    @Operation(summary = "测试接口1,打印hello")
    @GetMapping("/hello")
    public String hello(){
        return "hello,Spring boot...";
    }


}
